package amani.wechat.platform.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import amani.wechat.platform.services.IStorefrontService;
import amani.wechat.platform.webserviceClient.Designer;
import amani.wechat.platform.webserviceClient.Project;
import amani.wechat.platform.webserviceClient.Works;

@Controller
@RequestMapping("/Storefront")
public class StorefrontController {

	@Resource(name="StorefrontService")
	private IStorefrontService storefrontService;
	/**
	 * 到店首页
	 * @param model
	 * @return
	 */
	@RequestMapping("/index/mr")
	public String indexMr( Model model,String type) {
		model.addAttribute("type", "mr");
		System.out.println("美发");
		return "storefront/index";
	}
	
	/**
	 * 到店首页
	 * @param model
	 * @return
	 */
	@RequestMapping("/index/mf")
	public String indexMf( Model model,String type) {
		model.addAttribute("type", "mf");
		return "storefront/index";
	}
	
	/**
	 * 获取作品数据信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/works")
	@ResponseBody
	public List<Works> works( int page,double xcoordinate,double ycoordinate) {
		List<Works> worksList = storefrontService.pageWorks(page, xcoordinate, ycoordinate);
		//System.out.println("page:"+page+" | works size:"+worksList.size());
		return worksList;
	}
	
	/**
	 * 获取作品数据信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/worksByDesigner")
	@ResponseBody
	public List<Works> worksByDesigner( int page,String designer) {
		List<Works> worksList = storefrontService.pageWorks(page,designer);
		return worksList;
	}
	
	/**
	 * 作品详细信息页面
	 * @param model
	 * @return
	 */
	@RequestMapping("/workshow")
	public String workShow(int id, Model model) {
		Works works = storefrontService.getWorks(id);
		Designer designer = storefrontService.getDesigner(works.getDesigner().getValue());
		model.addAttribute("works", works);
		model.addAttribute("designer", designer);
		return "storefront/workshow";
	}
	
	/**
	 * 获取作品数据信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/projects")
	@ResponseBody
	public List<Project> projects(String type){
		List<Project> res = storefrontService.listProjects(type);
		return res;
	}
	
	/**
	 * 到店美容（身体、面部、套餐）
	 * @param model
	 * @return
	 */
	@RequestMapping("/detail/{type}/{id}")
	public String detail(@PathVariable Integer type, @PathVariable String id, Model model) {
		Map<String, Object> pro = storefrontService.getWchatProduct(id);
		model.addAttribute("pro", pro);
		if(type==3){//套餐
			List<Map<String, Object>> itemSet = storefrontService.getProductPackage(id);
			model.addAttribute("itemSet", itemSet);
			return "storefront/meal";
		}else{//面部或身体
			List<Map<String, Object>> stepSet = storefrontService.getProductDetail(id);
			model.addAttribute("stepSet", stepSet);
			return "storefront/detail";
		}
	}
}
